﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace SharpSoft
{
    /// <summary>
    /// 延时执行
    /// </summary>
    public static class Delay
    {
        public static void Run(Delegate deleg, int millisecondsDelay, params object[] paras)
        {
            Action action = new Action(delegate
            {
                System.Threading.Thread.Sleep(millisecondsDelay);
                deleg.DynamicInvoke(paras);
            });
            action.BeginInvoke(iar =>
            {
                action.EndInvoke(iar);
            }, null);

        }

        public static async void RunAsync(Delegate deleg, int millisecondsDelay, params object[] paras)
        {
            await Task.Delay(millisecondsDelay);
            deleg.DynamicInvoke(paras);
        }
    }
}
